﻿#ifndef COMMANDMANAGER_H
#define COMMANDMANAGER_H

#include <QObject>
#include <QMap>
#include "API_CommandManager.h"
#include "BaseModule/GlobalEnums.h"

#define CommandManagerInstance CommandManager::CommandManager::getInstance()

namespace CommandManager
{
    class CommandBase;

    /// @brief 命令管理类
    class API_COMMANDMANAGER CommandManager : public QObject
    {
    public:
        static CommandManager* getInstance();

        /// @brief 清除redo命令列表
        void clearRedoCommands();

        /// @brief 清除所有命令
        void clearAllCommands();

        /// @brief 获取undo列表大小
        /// @return undo列表大小
        int getUndoListSize();

        /// @brief 获取redo列表大小
        /// @return redo列表大小
        int getRedoListSize();

    public slots:

        /// @brief 执行命令
        /// @param command 命令
        /// @param state 状态，true成功，false失败
        void slot_execCommand(CommandBase* command, bool* state);

        /// @brief 执行命令管理
        /// @param commandType 
        void slot_execCommandManager(BaseModule::ECommandManager commandType);


    private:
        CommandManager();
        ~CommandManager() = default;

        /// @brief 撤销
        void undo();

        /// @brief 恢复
        void redo();

    private:
        static CommandManager* m_instance;//单例指针

        QList<CommandBase*> m_undoMap;   //算例ID对应的undo命令数组
        QList<CommandBase*> m_redoMap;   //算例ID对应的redo命令数组

    };

}

#endif // !COMMANDMANAGER_H
